package GIUAKI;

import java.awt.TexturePaint;
import java.awt.peer.SystemTrayPeer;
import java.util.Scanner;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

public class NhieuThread extends Thread{

	/**
	 * @param args
	 */
	int a,b;
	NhieuThread(int x,int y)
	{
		a=x;
		b=y;
	}
	public boolean TimNT(int n)
	{
		int dem=0;
		for(int i=1;i<n;i++)
		{
			if(n%i==0)
				dem=dem+1;
		}
		if(dem<=2)
			return true;
		return false;
	}
	public void run()
	{
		int count=0;
		long start=System.currentTimeMillis();
		for(int j=a;j<b;j++)
			if(TimNT(j)==true)
				count=count+1;
		long time=System.currentTimeMillis()-start;
		System.out.println("Thread ten "+this.getName()+" dem duoc "+count+" trong khoang thoi gian "+time+" ms");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int sothread,N;
		Scanner nhap=new Scanner(System.in);
		System.out.print("Ban nhap so thread vao di: ");
		sothread=nhap.nextInt();
		System.out.print("Ban nhap so N vao di: ");
		N=nhap.nextInt();
		NhieuThread[]th=new NhieuThread[sothread];
		int A=N/sothread;
		for(int i=0;i<sothread;i++)
		{
			th[i]=new NhieuThread(A*i+1, A*(i+1));
			th[i].start();
		}
		
		
	}

}
